using System;
using System.Collections.Generic;
using System.Text;

namespace Barbar.MapReport.Common {
  public struct VectorD {
    public double X;
    public double Y;

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    public VectorD(PointD point) {
      X = point.X;
      Y = point.Y;
    }

    public VectorD(double x, double y) {
      X = x;
      Y = y;
    }

    public VectorD UnitVector {
      get {
        double length = Length;
        if (length == 0.0)
          throw new ArithmeticException("Vector length is null");
        return new VectorD(X / length, Y / length);
      }
    }

    public VectorD NormalVector {
      get { return new VectorD(-Y, X); }
    }

    public static VectorD operator *(VectorD vector, double scalar) {
      return new VectorD(vector.X * scalar, vector.Y * scalar);
    }

    public double Length {
      get { return Math.Sqrt(X * X + Y * Y); }
    }

    public int LengthInt32 {
      get { return (int)Length; }
    }
  }
}
